package com.opennews.openplatform.familyexpenseapi.dto.bank.card

import com.fasterxml.jackson.annotation.JsonProperty
import com.opennews.openplatform.myspringbootcore.dto.IdentityDto
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Size

abstract class BaseBankCardDto {
    @field:NotNull(message = "bank can't be null")
    lateinit var bank: IdentityDto

    @field:NotBlank(message = "name can't be blank")
    @field:Size(max = 50, message = "name must be at most 50 characters")
    lateinit var name: String

    /** Example: "15" means the 15th of each month. */
    @field:Size(max = 50, message = "statementDate must be at most 50 characters")
    var statementDate: String? = null

    /** Example: "+3" means 3rd of next month as statementDate. "24" means 24th of the same month. */
    @field:Size(max = 50, message = "paymentDueDate must be at most 50 characters")
    var paymentDueDate: String? = null

    @field:Size(max = 50, message = "customerServiceNumber must be at most 50 characters")
    var customerServiceNumber: String? = null

    /**
    IMPORTANT!!!
    Without @JsonProperty("isCreditCard") you would find this field value will NOT be updated from request json data.
    The issue occurs because the naming convention for boolean fields in Java, particularly when using libraries like Jackson,
    can cause a mismatch between the JSON property and the generated getter/setter methods in your DTO.
    //
    - In Java, a boolean field named isCreditCard generates a getter named isCreditCard() by default.
    - However, Jackson maps the JSON property isCreditCard to the field by looking for a method named getIsCreditCard(),
    which doesn't // exist. Instead, it treats the field as if it were unset and defaults to false.
    */
    @JsonProperty("isCreditCard")
    var isCreditCard: Boolean = false

    var enabled: Boolean = true
}